// implementation of displayObj3D
// Graham Morgan and Jan Allbeck

#include "TexturedObj.h"


TexturedObj::TexturedObj() 
{
} 

TexturedObj::TexturedObj(char* filename, int newID) 
: PoseableObject( newID )
{

		// load up model
		dbLoadObject(filename, newID);

		// (no texture loaded)
		texture = -1;

		// collision with this object
		dbSetObjectCollisionToBoxes ( newID );

		// shadow for the object: should make this relative to object size!
		dbMakeObjectPlane		( newID + 2000 , 40 , 40 );
		dbXRotateObject			( newID + 2000 , -90 );
		dbTextureObject			( newID + 2000 , 3 );
		dbSetObjectTransparency ( newID + 2000 , 1 );
		dbSetObjectCollisionOff	( newID + 2000 );
}

///////////////////////////////////////////////
// Destructors are used to clean up memory
TexturedObj::~TexturedObj() {

	// remove model
	dbDeleteObject (this->getID());

	// remove texture if loaded
	if (texture != -1)
		dbDeleteObject (texture);
}

//////////////////////////////////////////////////////
// apply texture
void TexturedObj::applyTexture(char* filename) {

	dbLoadImage(filename, this->getID() + 1000);
	dbTextureObject (this->getID(), this->getID() + 1000);
	texture = getID() + 1000; 
}


//////////////////////////////////////////////
// return the object's texture ID
int 
TexturedObj::getTextureID() const
{
	return this->texture;
}


///////////////////////////////////////////////////////
// return a copy of the object's scale
Triple 
TexturedObj::getScale() const
{
	return this->scale;
}

///////////////////////////////////////////////////////
// return the x coordinate of the scale
float 
TexturedObj::getScaleX() const
{
	return this->scale.x;
}

///////////////////////////////////////////////////////
// return the y coordinate of the scale
float 
TexturedObj::getScaleY() const
{
	return this->scale.y;
}

///////////////////////////////////////////////////////
// return the z coordinate of the scale
float 
TexturedObj::getScaleZ() const
{
	return this->scale.z;
}


///////////////////////////////////////////////////////
// set the object's current position
void 
TexturedObj::setPosition(float x, float y, float z)
{
	PoseableObject::setPosition( x, y, z );

	// object's position
	dbPositionObject(this->getID(), x, y, z);

	// shadow's position
	dbPositionObject(this->getID() + 2000 , ( float )x, 0.1f , z);
}

///////////////////////////////////////////////////////
// set the object's current orientation
void 
TexturedObj::setRotation(float x, float y, float z)
{
	PoseableObject::setRotation( x, y, z );

	dbRotateObject(this->getID(), x, y, z);
}

///////////////////////////////////////////////////////
// set the object's current scale
void 
TexturedObj::setScale(float x, float y, float z)
{
	this->scale.x = x;
	this->scale.y = y;
	this->scale.z = z;

	dbScaleObject(this->getID(), x, y, z);
}

///////////////////////////////////////////////////////
// do not display this object
void 
TexturedObj::hide()
{
	dbHideObject(this->getID());
}

////////////////////////////////////////////////////////
// display this object
void 
TexturedObj::show()
{
	dbShowObject(this->getID());
}